package ec.edu.udla.fichamedica.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Widget;

import ec.edu.udla.fichamedica.shared.LoginInfo;

public class Home extends Composite implements HasText {

	private static HomeUiBinder uiBinder = GWT.create(HomeUiBinder.class);

	interface HomeUiBinder extends UiBinder<Widget, Home> {
	}

	public Home(LoginInfo loginInfo) {
		initWidget(uiBinder.createAndBindUi(this));
		if(loginInfo!=null){
		if (loginInfo.isLoggedIn()) {
			anchor.setText("Logout");
    	    anchor.setHref(loginInfo.getLogoutUrl());
    	    System.out.println("Ya esta logueado");
		} else {
			anchor.setText("Login");
			anchor.setHref(loginInfo.getLoginUrl());
			System.out.println("No esta logueado");
		}}else
		{
			System.out.println("login es null");
		}
		
		System.out.println("Fin constructor Home");
	}

	@UiField
	Button button;
	
	@UiField
	  Anchor anchor;

	public Home(String firstName) {
		initWidget(uiBinder.createAndBindUi(this));
		button.setText(firstName);
	}

	@UiHandler("button")
	void onClick(ClickEvent e) {
		Window.alert("Hello!");
	}

	public void setText(String text) {
		button.setText(text);
	}

	public String getText() {
		return button.getText();
	}

}
